/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mantenimiento.servlet.Mant;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mantenimiento.dao.MantenimientoDAO;
import mantenimiento.excepcion.DAOExcepcion;
import mantenimiento.modelo.Mantenimiento;

/**
 *
 * @author PFR
 */
public class MantenimientoInsertarServlet extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

       
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        //processRequest(request, response);
        String a = request.getParameter("fecha_ini");
        String b = request.getParameter("fecha_fin");
        String b2 = request.getParameter("id_maquina");
        String c = request.getParameter("descripcion");
        String d = request.getParameter("actividad");
        String e = request.getParameter("idusuario");
        String f = request.getParameter("tipoMant");
        String g = request.getParameter("criticidad");

System.out.println(f);
System.out.println(g);
        //int fecha_ini = a.length();
        int fecha_fin = b.length();
        int id_maquina = b2.length();

        int actividad = d.length();
        int idusuario = e.length();

        int criticidad = g.length();

         Mantenimiento vo = new Mantenimiento();
         vo.setFecha_ini(a);
         vo.setFecha_fin(b);
         vo.setEquipo_idequipo(Integer.parseInt(b2));
         vo.setDescripcion(c);

         vo.setCriticidad(g);
         vo.setEstado("a");
            
            
            vo.setIdusuario(e);
            vo.setTipo_mant(f);
            MantenimientoDAO dao = new MantenimientoDAO();
            try {
                dao.insertar(vo);
                RequestDispatcher rd = request.getRequestDispatcher("/mantenimiento.jsp");
                rd.forward(request, response);
            } catch (DAOExcepcion ex) {
                Logger.getLogger(MantenimientoInsertarServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
